--test setIcon ability to handle any image format and possible error
--if you have compiled your own qt make sure the image format is supported
--unfoumd icons should be ignored
--setting icons on unsupported objects can crash or force an assert
--
-- for now this is a visual test, remove the run when it works
--then can just test for crashing

include std/unittest.e
include qt/core.e as qt
include std/io.e
include std/error.e
include qt/qtUtils.e  as qu
include qt/debug_utils.e
include std/sequence.e

set_test_verbosity(TEST_SHOW_ALL)

atom t1= Timer(,6040)  --ms

object _ =  qt:init()

atom
	w  = qt:loadUi(read_file("test.ui")),
	b  = qt:findChild(w, "pushButton"),
	progressBar  = qt:findChild(w, "progressBar"),
	cb

printf(1, "win = %s\n%s\n", {
    qt:propget(w ,"objectName")  
    ,join(wrap_len(getChildrenNames(w ), 70,1), "\n")
})

 qt:propset(progressBar, "maximum", 105)
 qt:propset(progressBar, "minimum",0)
 qt:propset(progressBar, "value",2)



sequence icoloc="../images/"
sequence theicons= {
     "ico","png","jpg","bmp"
 }
--~ btn_ico btn_png btn_jpg btn_bmp
--~ menu+
--~ action+

--test ignore unfoumd icon
   b = qt:findChild(w, "btn_ico")
  setIcon(b, "notimages/eu4_32,") 

function OnQuit()
         stopTimer(t1)
		abort(0)
	return 0
end function
    atom actionQuit = qt:findChild(w, "actionOpenFile", "QAction")
 qt:propset(actionQuit, "shortcut", Qt_Key_Escape)
qt:connect(actionQuit, "triggered()", "slot()", routine_id("OnQuit"))
setAttribute(w, Qt_WA_DeleteOnClose)

--test can set all icons on buttons
sequence buttons= {
     "toolButton","radioButton","checkBox"
 }
for x = 1 to length(buttons) do
   cb = qt:findChild(w, buttons[x])
    if cb<=0 then crash(sprintf("find problem at %d %s",{x, theicons[x]})) 
    end if
    setIcon(cb, icoloc&"eu4_32."&theicons[1]) 
end for

--test can set icons on various buttons
for x = 1 to length(theicons) do
    cb = qt:findChild(w, "btn_"&theicons[x])
    if cb<=0 then crash(sprintf("find problem at %d %s",{x, theicons[x]})) 
    end if
    setIcon(cb, "images/eu4_32."&theicons[x]) 
end for




--~ test_equal("propget_struct b pos ",  "{10,20}", qt:propget_struct(b, "pos") )
qt:move(b, 11, 12)
test_equal("propget_struct b pos ", "{11,12}", qt:propget_struct(b, "pos") )


--this propset visable works the same as show()
--~ qt:propset(w, "visible" , 1)
qt:show(w)
    startTimer(t1)
    qt:connect(t1, "timeout()", "slot()", routine_id("OnQuit"))

--not sure how to automate testing this one
--~ qt_setTabOrder()


--test main icon with a model messagebox
for x = 1 to length(theicons) do
  qt:propset(progressBar, "value", x*20)
    setIcon(w, "images/eu4_32."&theicons[x]) 
    if QMessageBox_No = qt:question(0, "is icon set? "&theicons[x],
            tr("want to continue ?"),
            {QMessageBox_Yes,QMessageBox_No}) then
	exit
    end if
    stopTimer(t1)
end for

_ = qt:run()

test_report()

--buttons can show every type of the 4 currently testing
--think was having problems before using ico >32x32x32?
--yea, was 63x62x24bpp now is 32x32x24bpp but only 32 colors
--could be a win9x limitation though
--need to get smarter in setIcon 
--should check has a setIcon or a setWindowIcon
--but still need to cast untill can figure that out...
--maybe a qcast_macro will work better? but to what
--need to get an enumeration of every class for some of the tests
--and every plugin or widget available may be different on any given system
--moved the icons to ,,/images from texts/images and don't show in the buttons now
--~ but do show in the app icon and toolbutton icons
    --~ should cycle all of them on clicking and make it verbose
